//
// Created by LiuYou on 2021/8/12.
//

#include <cstdio>
#include <cstring>
#include <sys/socket.h>
#include <cassert>
#include <netinet/in.h>
#include <cstdlib>
#include <arpa/inet.h>
#include <unistd.h>


/**
 * 发送带外数据
 */
int main(int argc, char** argv) {
    if (argc < 3) {
        fprintf( stderr, "用法: %s ip port\n", basename( argv[0] ));
        return 1;
    }

    char* ip = argv[1];
    char* port = argv[2];


    sockaddr_in remoteAddress = {
            .sin_family=AF_INET,
            .sin_port=htons( atoi( port ))
    };
    inet_pton( AF_INET, ip, &remoteAddress.sin_addr );


    int socketFd = socket( PF_INET, SOCK_STREAM, 0 );
    assert( socketFd >= 0 );

    if (connect( socketFd, (sockaddr*) &remoteAddress, sizeof( remoteAddress )) < 0) {
        perror( "connect()" );
        close( socketFd );
        exit( 1 );
    }
    const char* oobData = "abc";
    const char* normalData = "123";

    send( socketFd, normalData, strlen( normalData ), 0 );
    send( socketFd, oobData, strlen( oobData ), MSG_OOB );
    send( socketFd, normalData, strlen( normalData ), 0 );


    close( socketFd );
    return 0;
}































